<template>
  <div>
    <el-dialog
      v-toggle-full
      v-loading.lock="loading"
      class="base-dialog order-details"
      :custom-class="'panna-dialog_big'"
      :append-to-body="true"
      title="入库单详情"
      align="center"
      :close-on-click-modal="false"
      :visible.sync="innerDialogFormVisible"
      @closed="closeDialog"
    >
      <!-- 入库单信息 -->
      <el-divider class="el-divider-specail" content-position="left"
        >入库单信息</el-divider
      >
      <el-form ref="formData" :model="formData" label-width="120px" status-icon>
        <el-row>
          <el-col :span="12">
            <el-form-item label="入库单号">
              {{ formData.orderNum }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入库仓库">
              {{ formData.storageName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="申请人">
              {{ formData.applicantName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请时间">
              {{ formData.createTime }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="业务类型">
              {{ formData.orderTypeName }}
            </el-form-item>
          </el-col>
            <el-col :span="12">
            <el-form-item label="处理人">
              {{ formData.conductorName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="申请原因">
              {{ formData.remark }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!-- 物料清单 -->
      <el-divider
        class="el-divider-specail el-divider-top"
        content-position="left"
        >物料清单</el-divider
      >
      <el-table
        v-if="formData.products.length > 0"
        :data="formData.products"
        :header-cell-style="{ height: '50px' }"
        :cell-style="{ height: '44px', overflow: 'auto' }"
        style="width: 100%; height: auto; overflow: auto"
      >
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="物料编号">
          <template slot-scope="scope">
            {{ scope.row.number }}
          </template>
        </el-table-column>
        <el-table-column label="物料名称">
          <template slot-scope="scope">
            {{ scope.row.name }}
          </template>
        </el-table-column>
        <el-table-column label="规格型号">
          <template slot-scope="scope">
            {{ scope.row.size }}
          </template>
        </el-table-column>
        <el-table-column label="分类">
          <template slot-scope="scope">
            {{ scope.row.typeName }}
          </template>
        </el-table-column>
        <el-table-column label="存储条件">
          <template slot-scope="scope">
            {{ scope.row.storeCondition }}
          </template>
        </el-table-column>
        <el-table-column label="包装单位">
          <template slot-scope="scope">
            {{ scope.row.packingUnit }}
          </template>
        </el-table-column>
        <el-table-column label="应收数量">
          <template slot-scope="scope">
            {{ scope.row.productCount }}
          </template>
        </el-table-column>
        <el-table-column label="实收数量">
          <template slot-scope="scope">
            {{ scope.row.actualCount }}
          </template>
        </el-table-column>
      </el-table>
      <!-- 入库明细 -->
      <el-divider
        class="el-divider-specail el-divider-top"
        content-position="left"
        >入库明细</el-divider
      >
      <el-table
        :data="formData.productDetails"
        :header-cell-style="{ height: '50px' }"
        :cell-style="{ height: '44px', overflow: 'auto' }"
        style="width: 100%; height: auto; overflow: auto"
      >
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="物料编号">
          <template slot-scope="scope">
            {{ scope.row.productNum }}
          </template>
        </el-table-column>
        <el-table-column label="物料名称">
          <template slot-scope="scope">
            {{ scope.row.productName }}
          </template>
        </el-table-column>
        <el-table-column label="规格型号">
          <template slot-scope="scope">
            {{ scope.row.size }}
          </template>
        </el-table-column>
        <el-table-column label="供应商">
          <template slot-scope="scope">
            {{ scope.row.supplierName }}
          </template>
        </el-table-column>
        <el-table-column label="证书编号">
          <template slot-scope="scope">
            {{ scope.row.certificateNum }}
          </template>
        </el-table-column>

        <el-table-column label="生产日期">
          <template slot-scope="scope">
            {{ scope.row.dateManufacture | dateTimeFormat }}
          </template>
        </el-table-column>
        <el-table-column label="入库数量">
          <template slot-scope="scope">
            {{ parseInt(scope.row.productCount) }}
          </template>
        </el-table-column>
        <el-table-column label="入库库区">
          <template slot-scope="scope">
            {{ scope.row.storageAreaName }}
          </template>
        </el-table-column>
        <el-table-column label="操作人">
          <template slot-scope="scope">
            {{ scope.row.operatorName }}
          </template>
        </el-table-column>
        <el-table-column label="操作时间">
          <template slot-scope="scope">
            {{ scope.row.createTime }}
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getInfo } from "../../../../api/Material/MaterialOrderIn.js";
import moment from 'moment';
export default {
  name: "RKOrderDetails",
  filters: {
    dateTimeFormat(dateTime) {
      if (!dateTime) {
        return dateTime;
      }
      return moment(dateTime).format("YYYY-MM-DD");
    },
  },
  props: {
    dialogDetailsVisible: {
      type: Boolean,
      default: false,
    },
    editId: {
      type: String,
      default: '',
    }
  },
  data() {
    return {
      loading: false,
      innerDialogFormVisible: false,
      dialogInspectResultVisible: false,
      formLabelWidth: "100px",
      initData: {
        id: 0,
        orderId: 0,
        orderNum: "",
        formTypeCode: 0,
        formTypeName: "",
        orderTypeCode: 0,
        orderTypeName: "",
        storageName: "",
        remark: "",
        applicantId: null,
        applicantName: null,
        products: [],
        productDetails: [],
      },
      formData: {
        id: 0,
        orderId: 0,
        orderNum: "",
        formTypeCode: 0,
        formTypeName: "",
        orderTypeCode: 0,
        orderTypeName: "",
        storageName: "",
        remark: "",
        applicantId: null,
        applicantName: null,
        createTime: null,
        products: [],
        productDetails: [],
      },
    };
  },
  watch: {
  },
  created() {
    this.innerDialogFormVisible = this.dialogDetailsVisible;
    this.init();
  },
  methods: {
    async init() {
      if (this.editId) {
        await this.getDetail();
      }
    },
    getDetail() {
      getInfo({ id: this.editId }).then((res) => {
        debugger
        this.formData = res.data;
        this.formData.orderId = this.formData.id;
        if (res.data && this.formData.products?.length > 0) {
          this.formData.products = res.data.products;
          this.formData.formTypeCode = 100;
          this.formData.formTypeName = '接受检查';
        }
        if (res.data && this.formData.ProductDetails?.length > 0) {
          this.formData.productDetails = res.data.productDetails;
        }
      });
    },
    cancel() {
      this.innerDialogFormVisible = false;
      this.$emit("update:dialogDetailsVisible", false);
      this.$refs["formData"].resetFields();
      this.$emit("update:editId", "");
    },
    closeDialog() {
      this.$parent.getList();
      this.cancel();
    },
  },
};
</script>
<style lang="scss">
.order-details {
  margin-top: 10px;
  width: 100%;

  .el-form {
    border: 1px solid #e6ebf5;

    .el-row {
      border-bottom: 1px solid #e6ebf5;

      &:last-child {
        border-bottom: none;
      }

      .el-col {
        &:nth-child(2n + 1) {
          .el-form-item {
            .el-form-item__label {
              border-left: none;
            }
          }
        }

        .el-form-item {
          margin: 0;
          height: 40px;
          line-height: 40px;

          .el-form-item__label {
            height: 100%;
            line-height: 40px;
            background: #f1f8ff;
            border-left: 1px solid #e6ebf5;
            border-right: 1px solid #e6ebf5;
            text-align: center;
            color: #909399;
            font-weight: bold;
          }

          .el-form-item__content {
            text-align: left;
            height: 100%;
            line-height: 40px;
            margin-left: 20px;
          }
        }
      }
    }
  }

  .el-divider-specail {
    background: transparent;

    .el-divider__text {
      font-weight: bold;
      font-size: 15px;
      left: -20px;
    }

    &.el-divider-top {
      margin-top: 30px;
    }
  }
}
</style>
